package org.yxj.zip4j;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import org.yxj.zip4jlibrary.CompressOperate_zip4j;
import org.yxj.zip4jlibrary.exception.ZipException;
import java.io.File;

public class MainActivity extends AppCompatActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED){
            ActivityCompat.requestPermissions(this,new String[]{
                    Manifest.permission.WRITE_SECURE_SETTINGS
            },1000);
        }

        findViewById(R.id.btn_unZipFile).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    String wgtPath=Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "jbh_goldRush/uni/wgt";
                    File[] f = CompressOperate_zip4j.unzip(path,wgtPath,"MjNRh0lOicqNomqSyRSCNJBRUIVtq4fK");
                    for (File file:f){
                        Log.v("[unZipFile]","file="+file.getAbsolutePath());
                    }
                } catch (ZipException e) {
                    e.printStackTrace();
                    Toast.makeText(MainActivity.this,"e="+e.getMessage(),Toast.LENGTH_SHORT).show();
                }
            }
        });
    }


    private String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "jbh_goldRush/uni/uniFile.zip";

}